// test_XRt1553B_InterruptHandler.c

#include "unity.h"
#include "xrt1553B.h"

// 测试变量
static int callback_call_count = 0;
static void* callback_param = NULL;

// Mock回调函数
void test_callback_function(void* CallBackRef) {
    callback_call_count++;
    callback_param = CallBackRef;
}

void setUp(void) {
    // 在每个测试前重置测试变量
    callback_call_count = 0;
    callback_param = NULL;
}

void tearDown(void) {
    // 测试后清理
}

// 测试用例1: InstancePtr为NULL
void test_XRt1553B_InterruptHandler_WhenInstancePtrIsNull_ShouldNotCallCallback(void) {
    // 执行
    XRt1553B_InterruptHandler(NULL);
    
    // 断言
    TEST_ASSERT_EQUAL(0, callback_call_count);
}

// 测试用例2: IntrHandler为NULL
void test_XRt1553B_InterruptHandler_WhenIntrHandlerIsNull_ShouldNotCallCallback(void) {
    // 准备
    XRt1553B instance = {0};
    instance.IntrHandler = NULL;
    instance.CallBackRef = (void*)0x12345678;
    
    // 执行
    XRt1553B_InterruptHandler(&instance);
    
    // 断言
    TEST_ASSERT_EQUAL(0, callback_call_count);
}

// 测试用例3: 正常情况 - 应回调函数并传入正确参数
void test_XRt1553B_InterruptHandler_WhenValidInstance_ShouldCallCallbackWithCorrectParam(void) {
    // 准备
    XRt1553B instance = {0};
    instance.IntrHandler = test_callback_function;
    instance.CallBackRef = (void*)0xABCDEF00;
    
    // 执行
    XRt1553B_InterruptHandler(&instance);
    
    // 断言
    TEST_ASSERT_EQUAL(1, callback_call_count);
    TEST_ASSERT_EQUAL_PTR((void*)0xABCDEF00, callback_param);
}

// 测试用例4: 回调参数为NULL
void test_XRt1553B_InterruptHandler_WhenCallbackParamIsNull_ShouldCallCallbackWithNullParam(void) {
    // 准备
    XRt1553B instance = {0};
    instance.IntrHandler = test_callback_function;
    instance.CallBackRef = NULL;
    
    // 执行
    XRt1553B_InterruptHandler(&instance);
    
    // 断言
    TEST_ASSERT_EQUAL(1, callback_call_count);
    TEST_ASSERT_NULL(callback_param);
}